home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions SangersFull component
-
- #include "NSDLL.h"
-
- /*************************************************************/
- /* Macros to access the PE layers and weights in matrix form */
-
- #define in(i,j) input[j+i*inCols]
- #define out(i,j) output[j+i*inCols]
- #define W(i,j) weights[j+i*inCount]
- #define Wt(i,j) weightsTranspose[i+j*outCount]
-
- float *weightsTranspose=NULL;
- int sangerInCountCheck=NULL,
- sangerOutCountCheck=NULL,
- transposeInCountCheck=NULL,
- transposeOutCountCheck=NULL;
-
- /******************************/
- /* Unsupervised weight update */
-
- __declspec(dllexport) void performUnsupervised(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to input layer
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *output, // Pointer to the output layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols, // Number of columns of PEs in the output layer
- NSFloat *weights, // Pointer to fully connected weight matrix
- NSFloat step // Learning rate
- )
- {
- int i, j,
- inCount=inRows*inCols,
- outCount=outRows*outCols;
- NSFloat partialSum;
-
- sangerInCountCheck = inCount;
- sangerOutCountCheck = outCount;
-
- if ( (sangerInCountCheck==transposeOutCountCheck) && (sangerOutCountCheck==transposeInCountCheck) )
- {
- for (j=0; j<inCount; j++) {
- partialSum = (NSFloat)0;
- for (i=0; i<outCount; i++) {
- partialSum += output[i] * W(i,j);
- W(i,j) += step*output[i]*(input[j] - partialSum);
- Wt(i,j) = W(i,j);
- }
- }
- }
- }
-
- __declspec(dllexport) void performFullSynapse(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to the input layer of processing elements (PEs)
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *output, // Pointer to the output layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols, // Number of columns of PEs in the output layer
- NSFloat *weights // Pointer to the fully connected matrix of weights
- )
- {
- int i, j,
- inCount=inRows*inCols,
- outCount=outRows*outCols;
-
- transposeInCountCheck = inCount;
- transposeOutCountCheck = outCount;
-
- if ( (sangerInCountCheck==transposeOutCountCheck) && (sangerOutCountCheck==transposeInCountCheck) )
- {
- weightsTranspose = weights;
- for (i=0; i<outCount; i++)
- for (j=0; j<inCount; j++)
- output[i] += W(i,j)*input[j];
- }
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocUnsupervised(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeUnsupervised(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */
-